home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
- # backup.od [ -a time ] [-m] [ dir ]
- # version 2.2, 11 July 1990.
- #
- # Back up files rooted at dir (default is $HOME) since last backup.
- # Backup is a tar file and is saved to /backup/$(USER) on
- # sv.<month>.<day>.<hour>.tar
- # where month, day and hour encode the date and time.
- # A long directory listing of all files backed up is saved to
- # sv.<month>.<day>.<hour>.lst.
- # Leaves a .backup.od file in dir, which lists the backup file,
- # date and time, and files backed up; the timestamp
- # of .backup.od file is used as time of `last backup'.
- #
- # If .backup.od doesn't exist or can't be read, all files are backed up
- # and the backup is saved to fl.<month>.<day>.<hour>.tar
- # where month, day and hour encode the date and time as above.
- # The long directory listing is stored in fl.<month>.<day>.<hour>.lst
- #
- # The -a option causes backup to schedule a backup at `time' and everyday
- # thereafter at the same time. Time is any time accepted by the at(1)
- # command. When the -a given, backup mails the standard output and error
- # of the backup run to the user.
- #
- # The -m option causes a request to mount an optical disk in drive 0 to be
- # issued before the backup is made. After the backup finished, the optical
- # disk will be unmounted and ejected.
- #
-
- # This script was originally written by Dr. Dave Hanson, Princeton University,
- # while at Los Alamos in the summer of 1987. It has been extensively modified
- # and ported to the NeXT by Pat McGee, Computer Graphics Group, Los Alamos National Laboratory.
-
- # Copyright, 1990, The Regents of the University of
- # California. This software was produced under a U. S.
- # Government contract (W-7405-ENG-36) by the Los Alamos
- # National Laboratory, which is operated by the
- # University of California for the U. S. Department of
- # Energy. The U. S. Government is licensed to use,
- # reproduce, and distribute this software. Permission
- # is granted to the public to copy and use this software
- # without charge, provided that this Notice and any statement
- # of authorship are reproduced on all copies. Neither the
- # Government nor the University makes any warranty, express
- # or implied, or assumes any liability or responsibility for
- # the use of this software.
-
- trap "rm -f /tmp/$$; exit 1" 1 2 15
-
- progname=$0
- timefile=.backup.od
-
- mount=
- at=
- attime=
- if [ "$1" = "-m" ]; then
- mount="-m"
- if [ "$2" = "-a" ]; then
- at="-a"
- attime=$3
- dir=${4-$HOME}
- else
- dir=${2-$HOME}
- fi
- elif [ "$1" = "-a" ]; then
- at="-a"
- attime=$2
- if [ "$3" = "-m" ]; then
- mount="-m"
- dir=${4-$HOME}
- else
- dir=${3-$HOME}
- fi
- else
- dir=${1-$HOME}
- fi
-
- if [ "$at" = "-a" ]; then
- SHELL=/bin/sh at $attime <<End
- $progname $mount $dir 2>&1 | mail -s "\`date\` $progname" $USER
- sleep 1200
- $progname $mount -a $attime $dir
- End
- exit 0
- fi
-
- #things to configure
- budir=/tmp/backup
- if [ "$mount" = "-m" ]; then
- savedir=${budir}
- else
- savedir=${budir}/$USER
- fi
-
- if [ "$mount" = "-m" ]; then
- mountod ${budir}
- fi
-
- if [ ! -d ${savedir} ]; then
- echo "${savedir} not found"
- exit 1
- fi
-
- cd $dir
- if [ ! -r ${timefile} ]; then
- #full backup
- basename=`date | tr A-Z: a-z'\040' | awk '{ printf "fl.%s.%02d.%s.", $2, $3, $4}'`
- savename=${basename}tar
- savedirname=${basename}lst
- if ls $savedir | grep $savename ; then
- echo "overwritten" ; fi
- find . ! -type d -print >/tmp/$$
- if tar cf ${savedir}/${savename} . ; then
- (echo $savedir/$savename `date`; cat /tmp/$$) >${timefile} ;
- else exit 1 ;
- fi
- echo "tar file written"
- rm -f /tmp/$$
- # comment out the next 3 lines to avoid writing the list file
- find . ! -type d -exec ls -l "{}" \; > /tmp/$$
- if cp /tmp/$$ ${savedir}/${savedirname} ; \
- then echo ; else exit ; fi
- # end of list file generation
- echo "backup.od done"
- df $savedir
- ls $savedir
- else
- # incremental backup
- basename=`date | tr A-Z: a-z'\040' | awk '{ printf "sv.%s.%02d.%s.", $2, $3, $4}'`
- savename=${basename}tar
- savedirname=${basename}lst
- if ls ${savedir} | grep $savename ; then echo \
- "file already exists" ; exit ; fi
- find . ! -type d -newer ${timefile} -print >/tmp/$$
- if tar cf ${savedir}/${savename} `cat /tmp/$$` ; \
- then (echo $savedir/$savename `date`; cat /tmp/$$) >${timefile} ;
- else exit 1 ; fi
- echo "tar file written"
- # comment out the next 3 lines to avoid writing the list file
- if ls -l `cat /tmp/$$` | \
- cat - > ${savedir}/${savedirname} ; then echo ; \
- else exit ; fi
- # end of list file generation
- echo "backup.od done"
- df $savedir
- ls $savedir
- fi
- rm -f /tmp/$$
- if [ "$mount" = "-m" ]; then
- unmountod
- fi
- exit 0
-